import { delay, http, HttpResponse } from 'msw';

import { UserApi } from '@/api/services/userService';

import { USER_LIST } from '../assets';

const signIn = http.post(`/api${UserApi.SignIn}`, async ({ request }) => {
  const { username, password } = await request.json();

  const user = USER_LIST.find((item) => item.username === username);

  if (!user || user.password !== password) {
    return HttpResponse.json({
      status: 10001,
      message: 'Incorrect username or password.',
    });
  }

  return HttpResponse.json({
    status: 0,
    message: '',
    data: {
      user,
      accessToken: "",
      refreshToken: "",
    },
  });
});

const userList = http.get('/api/user', async () => {
  // await delay(1000);
  return HttpResponse.json(
    Array.from({ length: 10 }).map(() => ({
      fullname: "",
      email: "",
      avatar: "",
      address: "",
    })),
    {
      status: 200,
    },
  );
});

// export default [signIn, userList];
export default [userList];
